package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 信用流水类型
 * @author xingxing.xiao
 * @date 2021/01/07 15:34
 */
@Getter
public enum CreditCardBillTypeEnum {

    /**
     * 订货单
     */
    ORDER("1", "enum.creditCardBillType.name.order", "", XbbRefTypeEnum.CONTRACT),
    /**
     * 厂商端展示回款单，经销商端展示付款单
     */
    PAYMENT_SHEET("2", "enum.creditCardBillType.name.payment_sheet", "", XbbRefTypeEnum.PAYMENT_SHEET),
    /**
     * 订货单关闭
     */
    ORDER_CLOSE("3", "enum.creditCardBillType.name.order_close", "", XbbRefTypeEnum.CONTRACT),
    /**
     * 订货单作废
     */
    ORDER_INVALID("4", "enum.creditCardBillType.name.order_invalid", "", XbbRefTypeEnum.CONTRACT),

    UNKNOWN("404", "--", "", XbbRefTypeEnum.UNKNOWN),
    ;

    /**
     * 状态
     */
    private String code;
    /**
     * 名称
     */
    private String name;
    /**
     *
     */
    private String attr;
    /**
     * 业务类型
     */
    private XbbRefTypeEnum xbbRefTypeEnum;

    CreditCardBillTypeEnum(String code, String name, String attr, XbbRefTypeEnum xbbRefTypeEnum) {
        this.code = code;
        this.name = name;
        this.attr = attr;
        this.xbbRefTypeEnum = xbbRefTypeEnum;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public static CreditCardBillTypeEnum getByCode(Integer code) {
        for (CreditCardBillTypeEnum cacheCode : values()) {
            if (Objects.equals(code, cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }
}
